package com.mac.macjetpackdemo

import android.app.Application
import android.content.Context
import android.os.StrictMode
import android.util.Log
import com.didichuxing.doraemonkit.DoraemonKit
import com.facebook.stetho.Stetho
import com.mac.macjetpackdemo.util.ContextUtil
import com.mac.macjetpackdemo.util.CrashHandler
import com.orhanobut.logger.AndroidLogAdapter
import com.orhanobut.logger.Logger
import com.qmuiteam.qmui.arch.QMUISwipeBackActivityManager
import com.stoa.floatlib.StoaFloat
import com.tencent.mmkv.MMKV

class App : Application() {
    companion object {
        private const val TAG = "App"
        lateinit var mContext: Context
    }

    override fun onCreate() {
        super.onCreate()
        mContext = applicationContext
        Stetho.initializeWithDefaults(this)
        ContextUtil.registerApp(this)
        Logger.addLogAdapter(AndroidLogAdapter())
        QMUISwipeBackActivityManager.init(this)
        CrashHandler.attach(this)
        val initialize = MMKV.initialize(this)
        Log.d(Companion.TAG, "onCreate: $initialize")
        initStrictMode()
        initDoraemonkit()

        StoaFloat.init(this)
    }

    private fun initStrictMode() {
        StrictMode.setThreadPolicy(
            StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog()
                .build()
        )
    }

    private fun initDoraemonkit(){
        DoraemonKit.install(this)
    }
}